package ${package}.${moduleName}.controller;



import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;;


@RestController
@RequestMapping("${className}")
@Tag(name="${tableComment}")
@AllArgsConstructor
public class ${ClassName}Controller {
    private final ${ClassName}ApplicationService ${className}ApplicationService;

    @PostMapping("page")
    @Operation(summary = "分页.")
    public ResponseEntity<List<${ClassName}PageResponse>> page(@RequestBody ${ClassName}PageRequest request,
                                                                           @Parameter(hidden = true) Paged paged) {
        PagedResult<${ClassName}> result = ${className}ApplicationService.page(paged);
        return Responses.pagedResult(${ClassName}Mapping.INSTANCE.toPageResponse(result));
    }

    @GetMapping("{id}")
    @Operation(summary = "详情")
    public ${ClassName}Response get(@PathVariable("id") String id){
        return ${ClassName}Mapping.INSTANCE.toInfo(${className}ApplicationService.ofId(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public void add(@RequestBody @Validated Add${ClassName}Request reqeust){
        Add${ClassName}Command command = ${ClassName}Mapping.INSTANCE.toAddCommand(reqeust);
        ${className}ApplicationService.add(command);
    }

    @PutMapping("/edit")
    @Operation(summary = "修改")
    public void edit(@RequestBody @Validated Edit${ClassName}Request request){
        Edit${ClassName}Command command = ${ClassName}Mapping.INSTANCE.toEditCommand(request);
        ${className}ApplicationService.edit(command);
    }

}